package org.seedltd.upms.service.impl.detection;

import org.seedltd.core.base.BaseServiceImpl;
import org.seedltd.core.utils.Assert;
import org.seedltd.core.utils.BeanUtils;
import org.seedltd.upms.mapper.detection.DetectionOrderBindingMapper;
import org.seedltd.upms.model.detection.entity.DetectionOrderBinding;
import org.seedltd.upms.model.detection.form.DetectionOrderBindingForm;
import org.seedltd.upms.model.detection.vo.DetectionOrderBindingVO;
import org.seedltd.upms.service.detection.DetectionOrderBindingService;
import org.springframework.stereotype.Service;

import lombok.AllArgsConstructor;

/**
 * 订单绑定信息业务实现
 * 
 * @author laizuan
 * @since 2021/07/31
 */
@Service
@AllArgsConstructor
public class DetectionOrderBindingServiceImpl extends
    BaseServiceImpl<DetectionOrderBindingMapper, DetectionOrderBinding> implements DetectionOrderBindingService {

    @Override
    public DetectionOrderBindingVO findByOrderId(Long orderId) {
        DetectionOrderBinding pojo = q().eq(DetectionOrderBinding::getOrderId, orderId).selectOne();

        if (pojo == null) {
            return null;
        }
        DetectionOrderBindingVO resultVo = new DetectionOrderBindingVO();
        BeanUtils.copyProperties(pojo, resultVo);
        return resultVo;
    }

    @Override
    public Long add(DetectionOrderBindingForm form) {
        DetectionOrderBinding pojo = new DetectionOrderBinding();
        BeanUtils.copyProperties(form, pojo);
        baseMapper.insert(pojo);
        return pojo.getId();
    }

    @Override
    public boolean update(DetectionOrderBindingForm form) {
        DetectionOrderBinding pojo = q().eq(DetectionOrderBinding::getOrderId, form.getOrderId()).selectOne();
        Assert.notNull(pojo, "未找到需要修改的数据");
        return u(pojo).updateById(form);
    }

}